package ryarithsGame;

import com.jme.bounding.BoundingSphere;
import com.jme.image.Texture;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;

public class Level7 extends Node 
{

	private PuzzleNode[] puzzle;
	private Goal goal;
	private static final long serialVersionUID = 1L;

	Node towerNode;
	
	public Level7()
	{
		super("Level7");
		loadPuzzle();
	}
	
	private void loadPuzzle()
	{
		goal = new Goal("goal", new Vector3f(100,15,100));
		puzzle = new PuzzleNode[1];
		puzzle[0] = new PuzzleNode("switch1", 0, new Vector3f(400,10,400),new Vector3f(100,10,100));
		//this.attachChild(goal);
		//this.attachChild(puzzle[0]);
		
		Box box = new Box("my box", new Vector3f(150f, 20, 150), 1, 20, 20);
	    box.setModelBound(new BoundingSphere());
	    box.updateModelBound();
	    
	    towerNode = new Node("tower");
        towerNode.attachChild(box);
        

        TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
        ts.setEnabled(true);
        Texture t2 = TextureManager.loadTexture(
                Level7.class.getClassLoader().getResource(
                "data/images/DragonGames1.png"),
            Texture.MinificationFilter.Trilinear,
            Texture.MagnificationFilter.Bilinear);
        t2.setWrap(Texture.WrapMode.Repeat);
        ts.setTexture(t2);
        
        towerNode.setRenderState(ts);
	    this.attachChild(towerNode);
		
	}
	
	public void updateLevel(float tpf)
	{
		puzzle[0].updatePuzzleNode(tpf);
		goal.updateGoalNode();	
	}
	
	public void checkSwitchCollisions(Vector2f camPos)
	{
		goal.checkSwitchCollisions(camPos);
	}
	
	public boolean getGoalSwitch()
	{
		//return goal.getIsSwitched();
		return true;
	}
	
	public PuzzleNode getPuzzleNode(int i)
	{
		return puzzle[i];
	}
	
	public int puzzleSize()
	{
		return puzzle.length;
	}
	
	public void detachAll()
	{
		this.detachAllChildren();
	}
}
